package cn.gok;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.function.Consumer;

public class HashMap的例子 {
    public static void main(String[] args) {
        //遍历();
        test();
    }

    private static void test() {
        System.out.println((int) 'A');
    }

    private static void 遍历() {
        Map<Integer, String> map = new HashMap<>();
        System.out.println(map.put(1, "aaa"));
        System.out.println(map.put(2, "bbb"));
        System.out.println(map.put(3, "ccc"));

        for (Integer key : map.keySet()) {
            String value = map.get(key);
            System.out.println(key + "---" + value);
        }
        System.out.println();
        Iterator<Integer> it = map.keySet().iterator();
        while (it.hasNext()){
            Integer key = it.next();
            String value = map.get(key);
            System.out.println(key + "---" + value);
        }
        System.out.println();
        //流遍历
        Consumer<Integer> con = (k)->{
            System.out.println(k+"---"+map.get(k));
        };
        map.keySet().stream().forEach(con);
        System.out.println("------");
        for (Map.Entry<Integer, String> e : map.entrySet()) {
            Integer key = e.getKey();
            String value = e.getValue();
            System.out.println(key + "---" + value);
        }
        System.out.println();
        Iterator<Map.Entry<Integer, String>> it2 = map.entrySet().iterator();
        while (it2.hasNext()){
            Map.Entry<Integer, String> e = it2.next();
            System.out.println(e.getKey() + "---" + e.getValue());
        }

        Consumer<Map.Entry<Integer,String>> con2 = (e) ->{
            System.out.println(e.getKey()+"---"+e.getValue());
        };
        map.entrySet().stream().forEach(con2);
    }
}
